
#ifndef __LIB_DRM_H_
#define __LIB_DRM_H_

#include "pt_include.h"
#include "pt_printk.h"


#define RED 	0XFF0000
#define GREEN   0X00FF00
#define BLUE 	0X0000FF


struct sp_dev {
    int fd;

    int num_connectors;
    drmModeConnectorPtr *connectors;

    int num_encoders;
    drmModeEncoderPtr *encoders;

    int num_crtcs;
    struct sp_crtc *crtcs;

    int num_planes;
    struct sp_plane *planes;

	uint32_t conn_id[6];
	uint32_t crtc_id[6];
};



struct sp_bo {
    struct sp_dev *dev;

    uint32_t width;
    uint32_t height;
    uint32_t depth;
    uint32_t bpp;
    uint32_t format;
    uint32_t flags;

    uint32_t fb_id;
    uint32_t handle;
    void *map_addr;
    uint32_t pitch;
    uint32_t size;
};

struct sp_plane {
    struct sp_dev *dev;
    drmModePlanePtr plane;
    struct sp_bo *bo;
    int in_use;
    uint32_t format;

    /* Property ID's */
    uint32_t crtc_pid;
    uint32_t fb_pid;
    uint32_t zpos_pid;
    uint32_t crtc_x_pid;
    uint32_t crtc_y_pid;
    uint32_t crtc_w_pid;
    uint32_t crtc_h_pid;
    uint32_t src_x_pid;
    uint32_t src_y_pid;
    uint32_t src_w_pid;
    uint32_t src_h_pid;
};

struct sp_crtc {
    drmModeCrtcPtr crtc;
    int pipe;
    int num_planes;
    struct sp_bo *scanout;
};


typedef struct _drm_device_fb {

	uint32_t  fb_w;				//显示器的宽的像素点数量
	uint32_t  fb_h;				//显示器的高的像素点数量
	uint32_t  fb_pitch;			//每行占据的字节数
	uint32_t  fb_hand;			//drm_mode_create_dumb的返回句柄
	uint32_t  fb_size;			//显示器占据的总字节数
	uint32_t *fb_vaddr;			//mmap的首地址
	uint32_t  fb_id;			//创建的framebuffer的id号

	struct drm_mode_create_dumb  fb_create ;	//创建的dumb
 	struct drm_mode_map_dumb     fb_map;		//内存映射结构体

}drm_device_fb;



typedef struct  _drm_para_t
{
	
	int 			  drm_fd;
	
	uint32_t 		  drm_crtc_id[12];
	uint32_t 		  drm_conn_id[12];
	uint32_t 		  drm_plane_id[24];
	
	drmModeRes 		 *drm_res;
	drmModePlaneRes  *drm_plane_res;
	drmModeConnector *drm_conn[12]; 

	drm_device_fb     drm_buff[12];
	
	drm_device_fb     drm_edp;
	drm_device_fb     drm_hdmi;

	struct sp_dev*    drm_dev;

	
	struct sp_plane * drm_Plane;

	
	struct sp_plane **drm_hdmi_plane;
	struct sp_crtc *  drm_hdmi_Crtc;
	struct sp_plane * drm_hdmi_show;


	struct sp_plane **drm_edp_plane;
	struct sp_crtc *  drm_edp_Crtc;
	struct sp_plane * drm_edp_show;

	
}drm_para_t;

















#endif

